class Solution {
public:
    int findClosestNumber(vector<int>& nums)
    {
        ranges::sort(nums);
        auto pos = ranges::lower_bound(nums, 0);
        if (pos == nums.end()) return nums.back();
        if (pos == nums.begin()) return *pos;
        return min(*pos, abs(*(pos - 1))) == *pos ? *pos : *(pos - 1);
    }
};